
# -*— coding: utf-8 -*-
import threading
import time, queue


class Producer(threading.Thread):
  def run(self):
    global q
    count = 0
    while True:
      if q.qsize() < 1000:
        for i in range(100):
          count += 1
          msg = 'release ' +str(count)
          q.put(msg)
          print(msg)
      time.sleep(1)
      

class Consumer(threading.Thread):
  def run(self):
    global q
    while True:
      if q.qsize() > 100:
        for i in range(3):
          msg = self.name + 'spent' + q.get()
          print(msg)
      time.sleep(1)
      

q = queue.Queue()

def main():

  for i in range(100):
    q.put('init product' + str(i))
  for i in range(2):
    p = Producer()
    p.start()
  for i in range(5):
    c = Consumer()
    c.start()


if __name__ == '__main__':
  main()


  

